package cn.com.paycn.ken.hbm;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Type;

@Entity
@Table(name="bbp_menu")
public class Menu
  implements Serializable
{
  private static final long serialVersionUID = -3628032997880730788L;

  @Id
  private Integer id;

  @Column(name="title", length=30)
  private String title;

  @Column(name="parent_id")
  private Integer parentId;

  @Column(name="sort")
  private Integer sort = Integer.valueOf(0);

  @Column(name="type", length=1)
  private String type;

  @Column(name="path", length=100)
  private String path;

  @Column(name="icon", length=20)
  private String icon;

  @Column(name="has_child")
  @Type(type="yes_no")
  private Boolean hasChild;

  @Transient
  private Boolean selected;

  @Transient
  private List<Menu> children;

  @ManyToMany(mappedBy="menus", targetEntity=Role.class)
  private Set<Role> roles = new HashSet();

  public String toString()
  {
    return String.format("{id:%s, parent:%s, title:%s, type:%s, sort:%s, hasChild:%s, selected:%s}", new Object[] { 
      this.id, this.parentId, this.title, this.type, this.sort, this.hasChild, this.selected });
  }

  public Integer getId() {
    return this.id;
  }
  public void setId(Integer id) {
    this.id = id;
  }
  public String getTitle() {
    return this.title;
  }
  public void setTitle(String title) {
    this.title = title;
  }
  public Integer getParentId() {
    return this.parentId;
  }
  public void setParentId(Integer parentId) {
    this.parentId = parentId;
  }
  public String getType() {
    return this.type;
  }
  public void setType(String type) {
    this.type = type;
  }
  public String getPath() {
    return this.path;
  }
  public void setPath(String path) {
    this.path = path;
  }
  public String getIcon() {
    return this.icon;
  }
  public void setIcon(String icon) {
    this.icon = icon;
  }
  public Integer getSort() {
    return this.sort;
  }
  public void setSort(Integer sort) {
    this.sort = sort;
  }
  public Set<Role> getRoles() {
    return this.roles;
  }
  public void setRoles(Set<Role> roles) {
    this.roles = roles;
  }

  public Boolean getHasChild() {
    return this.hasChild;
  }

  public void setHasChild(Boolean hasChild) {
    this.hasChild = hasChild;
  }

  public Boolean getSelected() {
    return this.selected;
  }

  public void setSelected(Boolean selected) {
    this.selected = selected;
  }

  public List<Menu> getChildren() {
    return this.children;
  }

  public void setChildren(List<Menu> children) {
    this.children = children;
  }
}